<?php
namespace Api\AjaxEvent
{
/**
 * Ajax event listener
 * @author Lukasz Torba
 */
 class Listener
 {
    protected $m_name = null;        // Actual event name
    protected $m_param = array();    // Actual event params
    protected $m_config = null;
    
     /**
      *  Event executor
      * @param $listener - listener name ( using to load module config )
      * @param $name - calling event parameter
      * @param $param - array of event parameters
      * @param $config - global config
      */
     public function __execute($listener, $event, array $param=array(), array $config=array())
     {
        $this->m_name = $event;
        $this->m_param = $param;
        
        
        $matched = array();
        if(preg_match('/^([a-zA-z0-9]+)\\\.*/',$listener,$matched))
        {         
            $moduleConfig = \Api\Config::Load($matched[1],false);
            $config = \Api\Config::Merge(array($moduleConfig, $config));
        }        
        
        $this->m_config = $config;
        
        echo $this->{$event}();
                        
     }
     
     /**
      *  Return actually called action
      */
     public function __eventGet_Action()
     {
        $action = \Api\ObjectLoader::GetObjectSession();        
        return json_encode(array(
            'action' => $action[\Api\ObjectLoader::C_ACTION]
            ));
     }
 }
}
?>